<?php
 

// SilverStripe Diary Module 0.0.2
// 17.07.2010
// Author:  nivanka@silverstripers.com

class Event extends DataObject{
	
	
	static $db = array(
		"Start" => "Date",
		"End" => "Date",
		"Content" => "HTMLText",
		"Title" => "Varchar",
		"StartTime" => "Time",
		"EndTime" => "Time",
		"Location" => "Varchar",
		"EventType" => "Varchar"
	);
	
	static $many_many = array(
      'Calendars' => 'CalendarHolder'
   	);

	function getCMSFields_forPopup(){

		$fields = new FieldSet();
		
		$fields->push(new TextField('Title', 'Title of the event' ));
		$fields->push(new TextField('EventType', 'Event Type'));
		$fields->push(new CalendarDateField('Start', 'Starting date' ));
		$fields->push(new CalendarDateField('End', 'Ending date' ));
		$fields->push(new TimeField('StartTime', 'Start Time', $value = "6:30pm",$timeformat = "G:i"));
		$fields->push(new TimeField('EndTime', 'End Time', $value = "6:30pm",$timeformat = "G:i"));
		$fields->push(new TextField('Location', 'Event Location'));
		$fields->push(new TextAreaField('Content', 'About the event' ));


		return $fields;

	}
	// Delete entry link
	function DeleteLink(){
		$calendar = DataObject::get_one("CalendarHolder");
		return $calendar->URLSegment . "/delete/?id=" . $this->ID;
	}
	
	//Edit entry link
	function EditLink(){
		$calendar = DataObject::get_one("CalendarHolder");
		return $calendar->URLSegment . "/edit/?id=" . $this->ID;
	}
	
	//View Link
	function ViewLink(){
		$calendar = DataObject::get_one("CalendarHolder");
		return $calendar->URLSegment . "/view/?id=" . $this->ID;
	}
	
	//View type Link
	function ViewTypeLink(){
		$calendar = DataObject::get_one("CalendarHolder");
		return $calendar->URLSegment . "/type/?name=" . strtolower($this->EventType);
	}
	//Edit the start time format
	function StartTimeE(){
		return substr($this->StartTime,0,5);
	}
	//Edit the end time format
	function EndTimeE(){
		return substr($this->EndTime,0,5);
	}
}

